<!DOCTYPE html>
<html lang="zh-cn" itemscope itemtype="http://schema.org/WebPage">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>学习opencv过程中python的梳理 - Tonser&#39;s blog</title>
  

<meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta name="MobileOptimized" content="width"/>
<meta name="HandheldFriendly" content="true"/>


<meta name="applicable-device" content="pc,mobile">

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">

<meta name="mobile-web-app-capable" content="yes">

<meta name="author" content="Tonser" />
  <meta name="description" content="最近有个课程需要用到opencv与python的学习，顺便梳理了一下知识点 " />

  <meta name="keywords" content="Tonser, blog, jane" />






<meta name="generator" content="Hugo 0.47" />


<link rel="canonical" href="https://sundxfansky.club/post/machine_vision/python_opencv_record/" />



<link rel="icon" href="/favicon.ico" />











<link rel="stylesheet" href="/sass/jane.min.aaf3394fc81ccb6f6fe3fe458d1f5b61c39f151e44df83baaf1d7b3775a8b98d.css" integrity="sha256-qvM5T8gcy29v4/5FjR9bYcOfFR5E34O6rx17N3WouY0=" media="screen">





<meta property="og:title" content="学习opencv过程中python的梳理" />
<meta property="og:description" content="最近有个课程需要用到opencv与python的学习，顺便梳理了一下知识点
" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://sundxfansky.club/post/machine_vision/python_opencv_record/" /><meta property="article:published_time" content="2019-03-08T01:37:53&#43;08:00"/>
<meta property="article:modified_time" content="2019-03-12T17:51:55&#43;08:00"/>
<meta itemprop="name" content="学习opencv过程中python的梳理">
<meta itemprop="description" content="最近有个课程需要用到opencv与python的学习，顺便梳理了一下知识点
">


<meta itemprop="datePublished" content="2019-03-08T01:37:53&#43;08:00" />
<meta itemprop="dateModified" content="2019-03-08T01:37:53&#43;08:00" />
<meta itemprop="wordCount" content="1517">



<meta itemprop="keywords" content="Code,Software Engineering," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="学习opencv过程中python的梳理"/>
<meta name="twitter:description" content="最近有个课程需要用到opencv与python的学习，顺便梳理了一下知识点
"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->




</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">细嗅蔷薇</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <li class="mobile-menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/">主页</a>
          
        
      </li><li class="mobile-menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/post/">文章</a>
          
        
      </li><li class="mobile-menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/tags/">标签</a>
          
        
      </li><li class="mobile-menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/categories/">分类</a>
          
        
      </li><li class="mobile-menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/about/">关于</a>
          
        
      </li>
    
  </ul>
</nav>


  
    






  <link rel="stylesheet" href="/lib/photoswipe/photoswipe.min.css" />
  <link rel="stylesheet" href="/lib/photoswipe/default-skin/default-skin.min.css" />




<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

<div class="pswp__bg"></div>

<div class="pswp__scroll-wrap">
    
    <div class="pswp__container">
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
    </div>
    
    <div class="pswp__ui pswp__ui--hidden">
    <div class="pswp__top-bar">
      
      <div class="pswp__counter"></div>
      <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
      <button class="pswp__button pswp__button--share" title="Share"></button>
      <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
      <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
      
      
      <div class="pswp__preloader">
        <div class="pswp__preloader__icn">
          <div class="pswp__preloader__cut">
            <div class="pswp__preloader__donut"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
      <div class="pswp__share-tooltip"></div>
    </div>
    <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
    </button>
    <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
    </button>
    <div class="pswp__caption">
      <div class="pswp__caption__center"></div>
    </div>
    </div>
    </div>
</div>

  

  

  <header id="header" class="header container">
    <div class="logo-wrapper">
  <a href="/" class="logo">
    
      细嗅蔷薇
    
  </a>
</div>

<nav class="site-navbar">
  <ul id="menu" class="menu">
    
    
        <li class="menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/">主页</a>
          

        

      </li>
    
        <li class="menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/post/">文章</a>
          

        

      </li>
    
        <li class="menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/tags/">标签</a>
          

        

      </li>
    
        <li class="menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/categories/">分类</a>
          

        

      </li>
    
        <li class="menu-item">
        
          
          
            <a class="menu-item-link" href="https://sundxfansky.club/about/">关于</a>
          

        

      </li>
    
    
  </ul>
</nav>

  </header>

  <div id="mobile-panel">
    <main id="main" class="main bg-llight">
      <div class="content-wrapper">
        <div id="content" class="content container">
          <article class="post bg-white">
    
    <header class="post-header">
      <h1 class="post-title">学习opencv过程中python的梳理</h1>
      
      <div class="post-meta">
        <time datetime="2019-03-08" class="post-time">
          2019-03-08
        </time>
        <div class="post-category">
            <a href="https://sundxfansky.club/categories/code/"> Code </a>
            
          </div>
        <span class="more-meta"> 约 1517 字 </span>
          <span class="more-meta"> 预计阅读 4 分钟 </span>

        
        

        
        
      </div>
    </header>

    
    
<div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content">
    <nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#python-中各种括号的区别">python 中各种括号的区别</a></li>
<li><a href="#正则表达式">正则表达式</a></li>
<li><a href="#安装anaconda-python-opencv中遇到的问题">安装anaconda python opencv中遇到的问题</a></li>
<li><a href="#python的枚举类">python的枚举类</a></li>
<li><a href="#python编程中的闭包加环境变量">python编程中的闭包加环境变量</a></li>
<li><a href="#匿名函数-lambda表达式">匿名函数(lambda表达式)</a></li>
<li><a href="#三元表达式">三元表达式</a></li>
<li><a href="#函数式编程">函数式编程</a>
<ul>
<li><a href="#map">MAP</a></li>
<li><a href="#reduce">reduce</a></li>
<li><a href="#filter">filter</a></li>
</ul></li>
<li><a href="#装饰器">装饰器</a></li>
</ul></li>
</ul>
</nav>
  </div>
</div>

    
    <div class="post-content">
      <p>最近有个课程需要用到opencv与python的学习，顺便梳理了一下知识点
</p>

<h2 id="python-中各种括号的区别">python 中各种括号的区别</h2>

<p>大括号{}，字典，dict</p>

<p>中括号[]，列表，list</p>

<p>小括号()，元组，tuple</p>

<h2 id="正则表达式">正则表达式</h2>

<p>在正则表达式中使用方法如下</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="kn">import</span> <span class="nn">re</span>
<span class="n">a</span> <span class="o">=</span> <span class="s1">&#39;python sdasd 68126 asd __ sda&#39;</span>
<span class="n">re</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s1">&#39;[这里放需要匹配的字符]{数字，如3,6,9,}&#39;</span><span class="p">,</span><span class="n">a</span><span class="p">)</span>
<span class="c1"># 上述为贪婪模式</span>
<span class="c1"># 返回的a 就是匹配的内容，为list</span>
<span class="c1"># 注意贪婪模式！！！！大部分该部分的bug的原因</span>
<span class="c1"># python 使用的时贪婪模式，当时用贪婪模式的时候为在大括号后面加个？即可 如</span>
<span class="n">re</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s1">&#39;[这里放需要匹配的字符]{数字，如3,6,9,}?&#39;</span><span class="p">,</span><span class="n">a</span><span class="p">)</span>
<span class="n">s</span>
<span class="c1"># .	代表任意字符</span>
<span class="c1"># |	逻辑或操作符</span>
<span class="c1"># [ ]	匹配内部的任一字符或子表达式</span>
<span class="c1"># [^]	对字符集和取非</span>
<span class="c1"># -	定义一个区间</span>
<span class="c1"># \	对下一字符取非（通常是普通变特殊，特殊变普通）</span>
<span class="c1"># *	匹配前面的字符或者子表达式0次或多次</span>
<span class="c1"># *?	惰性匹配上一个</span>
<span class="c1"># +	匹配前一个字符或子表达式一次或多次</span>
<span class="c1"># +?	惰性匹配上一个</span>
<span class="c1"># ?	匹配前一个字符或子表达式0次或1次重复</span>
<span class="c1"># {n}	匹配前一个字符或子表达式</span>
<span class="c1"># {m,n}	匹配前一个字符或子表达式至少m次至多n次</span>
<span class="c1"># {n,}	匹配前一个字符或者子表达式至少n次</span>
<span class="c1"># {n,}?	前一个的惰性匹配</span>
<span class="c1"># ^	匹配字符串的开头</span>
<span class="c1"># \A	匹配字符串开头</span>
<span class="c1"># $	匹配字符串结束</span>
<span class="c1"># [\b]	退格字符</span>
<span class="c1"># \c	匹配一个控制字符</span>
<span class="c1"># \d	匹配任意数字</span>
<span class="c1"># \D	匹配数字以外的字符</span>
<span class="c1"># \t	匹配制表符</span>
<span class="c1"># \w	匹配任意数字字母下划线</span>
<span class="c1"># \W	不匹配数字字母下划线</span></code></pre></td></tr></table>
</div>
</div>
<h2 id="安装anaconda-python-opencv中遇到的问题">安装anaconda python opencv中遇到的问题</h2>

<p>基本上按照安装 anaconda 基本过程就可以，可以添加好path，也可以后面再加，系统给其添加的path为</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></pre></td>
<td class="lntd">
<pre class="chroma">C:\Users\sundx\Anaconda3;
C:\Users\sundx\Anaconda3\Library\mingw-w64\bin;
C:\Users\sundx\Anaconda3\Library\usr\bin;
C:\Users\sundx\Anaconda3\Library\bin;
C:\Users\sundx\Anaconda3\Scripts;</pre></td></tr></table>
</div>
</div>
<p>这个后面会用到，在pycharm中设置时，先设置interpreter ，路径为<code>C:\Users\sundx\Anaconda3\python.exe</code></p>

<p>设置完成后会自动读取包含的包。之后python console打开不正常，之后可以在pycharm设置中对python console 中添加<code>name</code>为PATH的环境变量，内容为复制上述内容即可。
至此有关python的opencv 与pycharm的配置完成</p>

<h2 id="python的枚举类">python的枚举类</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span>
<span class="k">class</span> <span class="nc">VIP</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
    <span class="n">YELLOW</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="n">GREEN</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span>


<span class="n">VIP</span><span class="o">.</span><span class="n">YELLOW</span> <span class="c1"># 获取的就是枚举类本身</span>
<span class="n">VIP</span><span class="o">.</span><span class="n">YELLOW</span><span class="o">.</span><span class="n">value</span> <span class="c1"># 获取值</span>
<span class="c1"># 枚举类的特点 就是作为标签，不必了解值为多少，这就是枚举的意义。</span>
<span class="c1"># 应当确认大写，规则，不可变，防止重复，很有效，使用字典或正常的类，是可变，而且不防止相同的类型</span>
<span class="c1"># 枚举的类型，名字，值，同时可以遍历使用 for 循环</span>
<span class="c1"># 可以使用别名 使用相同的值，但是使用遍历 不会显示，会认为是别名</span>
<span class="c1"># 软件工程有23种设计模式，其中有单例模式，和枚举类的设计方法很相似</span></code></pre></td></tr></table>
</div>
</div>
<h2 id="python编程中的闭包加环境变量">python编程中的闭包加环境变量</h2>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="k">def</span> <span class="nf">cure</span><span class="p">():</span>
    <span class="c1"># 可以在这里面加入环境变量</span>
    <span class="k">def</span> <span class="nf">cue_1</span><span class="p">()</span>
    <span class="k">print</span><span class="p">(</span><span class="s2">&#34;1&#34;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">cue_1</span>
    <span class="c1"># 这就是一个闭包，闭包=环境变量+函数</span>
    <span class="c1"># 闭包内部的函数可以使用 `nonlocal` 关键字来继承或者认为在该闭包内的变量是全局 </span></code></pre></td></tr></table>
</div>
</div>
<h2 id="匿名函数-lambda表达式">匿名函数(lambda表达式)</h2>

<p>使用匿名函数使用lambda 定义即可。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">x</span><span class="o">+</span><span class="n">y</span>

<span class="n">f</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">:</span> <span class="n">x</span><span class="o">+</span><span class="n">y</span>
<span class="k">lambda</span> <span class="n">para_lsit</span><span class="p">:</span> <span class="n">expression</span>
<span class="n">f</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="n">add</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="c1">#结果相同</span></code></pre></td></tr></table>
</div>
</div>
<h2 id="三元表达式">三元表达式</h2>

<p>在C/C++中 <code>x&gt;y?x:y</code></p>

<p>在python中 <code>x if x&gt;y else y</code></p>

<h2 id="函数式编程">函数式编程</h2>

<h3 id="map">MAP</h3>

<p><strong>推荐多多使用</strong></p>

<p>ap是一个类,执行for循环，并注意与lambda表达式结合,精简，优美，可读性高</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="k">def</span> <span class="nf">square</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">x</span><span class="o">*</span><span class="n">x</span>
<span class="n">list_x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]</span>
<span class="n">list_y</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="n">square</span><span class="p">,</span><span class="n">list_x</span><span class="p">)</span>
<span class="n">list_y</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">*</span><span class="n">x</span><span class="p">,</span><span class="n">list_x</span><span class="p">)</span>
<span class="err">对于多个变量</span>
<span class="n">list_z</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">:</span> <span class="n">x</span><span class="o">*</span><span class="n">x</span><span class="o">+</span><span class="n">y</span> <span class="p">,</span><span class="n">list_x</span><span class="p">,</span><span class="n">list_y</span><span class="p">)</span></code></pre></td></tr></table>
</div>
</div>
<h3 id="reduce">reduce</h3>

<p>连续计算，连续调用lambda，递归调入参数</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="nb">reduce</span>
<span class="n">list_x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]</span>
<span class="nb">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">:</span><span class="n">x</span><span class="o">+</span><span class="n">y</span><span class="p">,</span><span class="n">list_x</span><span class="p">)</span></code></pre></td></tr></table>
</div>
</div>
<h3 id="filter">filter</h3>

<p>过滤掉不需要的内容</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-python" data-lang="python"><span class="n">list_x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span>
<span class="n">r</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="bp">True</span> <span class="k">if</span> <span class="n">x</span><span class="o">&gt;</span><span class="mi">0</span> <span class="k">else</span> <span class="bp">False</span><span class="p">,</span><span class="n">list_x</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">r</span><span class="p">))</span>
<span class="c1">#结果为1，1，10，1</span></code></pre></td></tr></table>
</div>
</div>
<h2 id="装饰器">装饰器</h2>

<p>在使用python中，最多使用的代码的，高级用法就是装饰器。</p>
    </div>

    
    
<div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">Tonser</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">2019-03-12</span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a></span>
  </p>
</div>


    
    

    <footer class="post-footer">
      <div class="post-tags">
          <a href="https://sundxfansky.club/tags/code/">Code</a>
          <a href="https://sundxfansky.club/tags/software-engineering/">Software Engineering</a>
          
        </div>

      
      <nav class="post-nav">
        
        
          <a class="next" href="/post/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B%E7%AC%94%E8%AE%B0/1/">
            <span class="next-text nav-default">软件工程笔记（一）</span>
            <span class="prev-text nav-mobile">下一篇</span>
            
            <i class="iconfont">
              <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  width="18" height="18">
  <path d="M332.091514 74.487481l-75.369571 89.491197c-10.963703 12.998035-10.285251 32.864502 1.499144 44.378743l286.278095 300.375162L266.565125 819.058374c-11.338233 12.190647-11.035334 32.285311 0.638543 44.850487l80.46666 86.564541c11.680017 12.583596 30.356378 12.893658 41.662889 0.716314l377.434212-421.426145c11.332093-12.183484 11.041474-32.266891-0.657986-44.844348l-80.46666-86.564541c-1.772366-1.910513-3.706415-3.533476-5.750981-4.877077L373.270379 71.774697C361.493148 60.273758 343.054193 61.470003 332.091514 74.487481z"></path>
</svg>

            </i>
          </a>
      </nav>
    </footer>
  </article>

  
  

  
  

  
  
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "sundxfansky/comments_blog"
            issue-term="pathname"
            crossorigin="anonymous"
            async>
      </script>
    </div>
  

  

  

  
  
    



        </div>
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
  
  
    <a href="mailto:sundxfansky@sjtu.edu.cn" rel="me noopener" class="iconfont"
      title="email" >
      <svg class="icon" viewBox="0 0 1451 1024" version="1.1"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  width="36" height="36">
  <path d="M664.781909 681.472759 0 97.881301C0 3.997201 71.046997 0 71.046997 0L474.477909 0 961.649408 0 1361.641813 0C1361.641813 0 1432.688811 3.997201 1432.688811 97.881301L771.345323 681.472759C771.345323 681.472759 764.482731 685.154773 753.594283 688.65053L753.594283 688.664858C741.602731 693.493018 729.424896 695.068979 718.077952 694.839748 706.731093 695.068979 694.553173 693.493018 682.561621 688.664858L682.561621 688.65053C671.644501 685.140446 664.781909 681.472759 664.781909 681.472759L664.781909 681.472759ZM718.063616 811.603883C693.779541 811.016482 658.879232 802.205449 619.10784 767.734955 542.989056 701.759633 0 212.052267 0 212.052267L0 942.809523C0 942.809523 0 1024 83.726336 1024L682.532949 1024 753.579947 1024 1348.948139 1024C1432.688811 1024 1432.688811 942.809523 1432.688811 942.809523L1432.688811 212.052267C1432.688811 212.052267 893.138176 701.759633 817.019477 767.734955 777.248 802.205449 742.347691 811.03081 718.063616 811.603883L718.063616 811.603883Z"></path>
</svg>

    </a>
  
    <a href="https://github.com/sundxfansky" rel="me noopener" class="iconfont"
      title="github"  target="_blank"
      >
      <svg class="icon" style="" viewBox="0 0 1024 1024" version="1.1"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  width="36" height="36">
  <path d="M512 12.672c-282.88 0-512 229.248-512 512 0 226.261333 146.688 418.133333 350.08 485.76 25.6 4.821333 34.986667-11.008 34.986667-24.618667 0-12.16-0.426667-44.373333-0.64-87.04-142.421333 30.890667-172.458667-68.693333-172.458667-68.693333C188.672 770.986667 155.008 755.2 155.008 755.2c-46.378667-31.744 3.584-31.104 3.584-31.104 51.413333 3.584 78.421333 52.736 78.421333 52.736 45.653333 78.293333 119.850667 55.68 149.12 42.581333 4.608-33.109333 17.792-55.68 32.426667-68.48-113.706667-12.8-233.216-56.832-233.216-253.013333 0-55.893333 19.84-101.546667 52.693333-137.386667-5.76-12.928-23.04-64.981333 4.48-135.509333 0 0 42.88-13.738667 140.8 52.48 40.96-11.392 84.48-17.024 128-17.28 43.52 0.256 87.04 5.888 128 17.28 97.28-66.218667 140.16-52.48 140.16-52.48 27.52 70.528 10.24 122.581333 5.12 135.509333 32.64 35.84 52.48 81.493333 52.48 137.386667 0 196.693333-119.68 240-233.6 252.586667 17.92 15.36 34.56 46.762667 34.56 94.72 0 68.522667-0.64 123.562667-0.64 140.202666 0 13.44 8.96 29.44 35.2 24.32C877.44 942.592 1024 750.592 1024 524.672c0-282.752-229.248-512-512-512"></path>
</svg>

    </a>


<a href="https://sundxfansky.club/index.xml" rel="noopener alternate" type="application/rss&#43;xml"
    class="iconfont" title="rss" target="_blank">
    <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  width="30" height="30">
  <path d="M819.157333 1024C819.157333 574.592 449.408 204.8 0 204.8V0c561.706667 0 1024 462.293333 1024 1024h-204.842667zM140.416 743.04a140.8 140.8 0 0 1 140.501333 140.586667A140.928 140.928 0 0 1 140.074667 1024C62.72 1024 0 961.109333 0 883.626667s62.933333-140.544 140.416-140.586667zM678.784 1024h-199.04c0-263.210667-216.533333-479.786667-479.744-479.786667V345.173333c372.352 0 678.784 306.517333 678.784 678.826667z"></path>
</svg>

  </a>
  
</div>

<div class="copyright">
  <span class="power-by">
    Powered by <a class="hexo-link" href="https://gohugo.io">Hugo</a>
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    Theme - <a class="theme-link" href="https://github.com/xianmin/hugo-theme-jane">Jane</a>
  </span>

  <span class="copyright-year">
    &copy;
    
      2017 -
    2019
    <span class="heart">
      
      <i class="iconfont">
        <svg class="icon" viewBox="0 0 1025 1024" version="1.1"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  width="14" height="14">
  <path d="M1000.1 247.9c-15.5-37.3-37.6-70.6-65.7-98.9-54.4-54.8-125.8-85-201-85-85.7 0-166 39-221.4 107.4C456.6 103 376.3 64 290.6 64c-75.1 0-146.5 30.4-201.1 85.6-28.2 28.5-50.4 61.9-65.8 99.3-16 38.8-24 79.9-23.6 122.2 0.7 91.7 40.1 177.2 108.1 234.8 3.1 2.6 6 5.1 8.9 7.8 14.9 13.4 58 52.8 112.6 102.7 93.5 85.5 209.9 191.9 257.5 234.2 7 6.1 15.8 9.5 24.9 9.5 9.2 0 18.1-3.4 24.9-9.5 34.5-30.7 105.8-95.9 181.4-165 74.2-67.8 150.9-138 195.8-178.2 69.5-57.9 109.6-144.4 109.9-237.3 0.1-42.5-8-83.6-24-122.2z"
   fill="#8a8a8a"></path>
</svg>

      </i>
    </span><span class="author">
        Tonser
        
      </span></span>

  
  
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont">
        
        <svg class="icon" viewBox="0 0 1024 1024" version="1.1"
  xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  width="35" height="35">
  <path d="M510.866688 227.694839 95.449397 629.218702l235.761562 0-2.057869 328.796468 362.40389 0L691.55698 628.188232l241.942331-3.089361L510.866688 227.694839zM63.840492 63.962777l894.052392 0 0 131.813095L63.840492 195.775872 63.840492 63.962777 63.840492 63.962777zM63.840492 63.962777"></path>
</svg>

      </i>
    </div>
  </div>
  
<script type="text/javascript" src="/lib/jquery/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="/lib/slideout/slideout-1.0.1.min.js"></script>




<script type="text/javascript" src="/js/main.dee43230127a73d039a734510fa896c89c3c7ce0cf0be0c7a7433f8fd69b76dc.js" integrity="sha256-3uQyMBJ6c9A5pzRRD6iWyJw8fODPC&#43;DHp0M/j9abdtw="></script>






  
    <script type="text/javascript" src="/js/load-photoswipe.js"></script>
    <script type="text/javascript" src="/lib/photoswipe/photoswipe.min.js"></script>
    <script type="text/javascript" src="/lib/photoswipe/photoswipe-ui-default.min.js"></script>
  













</body>
</html>
